home *** CD-ROM | disk | FTP | other *** search
- Path: news1.radix.net!news
- From: jfw@radix.net (Jim Ward)
- Newsgroups: comp.lang.c
- Subject: Re: How do I round and truncate floats to integers?
- Date: 20 Feb 1996 02:18:01 GMT
- Organization: RadixNet Internet Services
- Message-ID: <4gbb0p$c7s@news1.radix.net>
- References: <4g009b$c2n@news.tuwien.ac.at>
- NNTP-Posting-Host: dialin4.annex1.radix.net
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <4g009b$c2n@news.tuwien.ac.at>, sor@rs6.iaee.tuwien.ac.at says...
- >Given a float (double, to be exact) how do I
- >
- >1) round it to nearest integer (forget 0.5 problem for the moment) and
-
- A technique that also works for both positive and negative numbers is:
-
- (int) x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5);
-
- I got this from p.135 of Plauger's The Standard C Library.
-
-